-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib, treewide: introduce repoRevToName
and use it to cleanup most fetch*
functions
#316668
base: master
Are you sure you want to change the base?
Conversation
repoRevToName
and use to cleanup most fetch*
functionsrepoRevToName
and use it to cleanup most fetch*
functions
@@ -254,6 +254,64 @@ let | |||
outPath = builtins.path { inherit filter name; path = origSrc; }; | |||
}; | |||
|
|||
# urlToName : (URL | Path | String) -> String | |||
# | |||
# Transform a URL (or path, or string) into a clean package name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I can be wrong, but the general term is URI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a thing more general than a URL? Yes. But here it is literally "a URL, or a path, or a string (a package name, usually)".
# /nix/store paths. | ||
# | ||
# This uses a different implementation depending on the `pretty` argument: | ||
# false -> name everything as "source" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I do not like dual-type attributes. This is a serious footgun in a duck-typed language.
And let's remember Nix is not stellar on the error report department:
https://discourse.nixos.org/t/rant-finding-errors-in-module-configs-after-incompatible-upgrades-is-dreadful/46375
Either is everything a string, say format ? "short", "medium", "long"
or we stick to only two options (and then we can use a Boolean).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it is not checked by Nix but by the config.nix
and NixOS typing infra, and the errors it generates are pretty nice, e.g. with nameSourcesPrettily = "error"
:
$ nix-instantiate ./default.nix -A xlife
error: A definition for option `nameSourcesPrettily' is not of type `boolean or value "full" (singular enum)'. Definition values:
- In `nixpkgs.config': "error"
(use '--show-trace' to show detailed location information)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, less bad.
Nonetheless, semantically it is a clear case for an enumeration with three possible states, instead of a weird Boolean-plus-an-extra.
@@ -50,6 +50,39 @@ let | |||
default = false; | |||
}; | |||
|
|||
nameSourcesPrettily = mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nameSourcesPrettily = mkOption { | |
usePrettierSourceNames = mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, but why? nameSourcesPrettily
is shorter and means the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's shorter because it is more obscure.
verb-adjective-name is clearer than name-name-adverb.
On the other hand, it depends on the previous tristate vs boolean-plus-state discussion.
…ctions This patch adds `lib.repoRevToName` function that generalizes away most of the code used for derivation name generation by `fetch*` functions (`fetchzip`, `fetchFromGitHub`, etc, except those which are delayed until latter commits for mass-rebuild reasons). It's first argument controls how the resulting name will look (see below). Since `lib` has no equivalent of Nixpkgs' `config`, this patch adds `config.nameSourcesPrettily` option to Nixpkgs and then re-exposes `lib.repoRevToName config.nameSourcesPrettily` expression as `pkgs.repoRevToNameMaybe` which is then used in `fetch*` derivations. The result is that different values of `config.nameSourcesPrettily` now control how the `src` derivations produced by `fetch*` functions are to be named, e.g.: - `nameSourcesPrettily = false` (the default): ``` $ nix-instantiate -A fuse.src /nix/store/<hash>-source.drv ``` - `nameSourcesPrettily = true`: ``` $ nix-instantiate -A fuse.src /nix/store/<hash>-libfuse-2.9.9-source.drv ``` - `nameSourcesPrettily = "full"`: ``` $ nix-instantiate -A fuse.src /nix/store/<hash>-libfuse-2.9.9-github-source.drv ``` See documentation of `config.nameSourcesPrettily` for more info.
This is slightly more efficient.
38ffa76
to
a09a1e7
Compare
This a first half of #49862. Basically, this is a noop cleanup that keeps all the
fetch*
names as they are now, while introducing the newconfig.nameSourcesPrettily
option.Changes
lib, treewide: introduce
repoRevToName
, use it in mostfetch*
functionsThis patch adds
lib.repoRevToName
function that generalizes away most of the code used for derivation name generation byfetch*
functions (fetchzip
,fetchFromGitHub
, etc, except those which are delayed until latter commits for mass-rebuild reasons).It's first argument controls how the resulting name will look (see below).
Since
lib
has no equivalent of Nixpkgs'config
, this patch addsconfig.nameSourcesPrettily
option to Nixpkgs and then re-exposeslib.repoRevToName config.nameSourcesPrettily
expression aspkgs.repoRevToNameMaybe
which is then used infetch*
derivations.The result is that different values of
config.nameSourcesPrettily
now control how thesrc
derivations produced byfetch*
functions are to be named, e.g.:nameSourcesPrettily = false
(the default):nameSourcesPrettily = true
:nameSourcesPrettily = "full"
:See documentation of
config.nameSourcesPrettily
for more info.fetchsvn: move the name generator outside of the thunk
This is slightly more efficient.